

package com.hazelcast.spi.impl.servicemanager;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.function.Consumer;

/**
 * Responsible for managing services.
 */
public interface ServiceManager {

    /**
     * Gets the ServiceInfo for a service by serviceName.
     *
     * @param serviceName the name of the service.
     * @return the found ServiceInfo or null if nothing is found.
     */
    ServiceInfo getServiceInfo(@Nonnull String serviceName);

    /**
     * Gets all the service info's for services that implement a given class/interface.
     *
     * @param serviceClass the class/interface the service should implement.
     * @return a List of the found ServiceInfo. List will be empty if nothing is found.
     */
    List<ServiceInfo> getServiceInfos(Class serviceClass);

    /**
     * Gets a Service by serviceName.
     *
     * @param serviceName the name of the service.
     * @return the found service or null if nothing is found.
     */
    <T> T getService(@Nonnull String serviceName);

    /**
     * Gets all services implementing a certain class/interface.
     *
     * <b>CoreServices will be placed at the beginning of the list.</b>
     *
     * @param serviceClass the class/interface to check for.
     * @return the found services.
     */
    <S> List<S> getServices(Class<S> serviceClass);

    /**
     * @param serviceClass the class/interface the service should implement.
     * @param consumer     to consume {@link ServiceInfo}
     */
    void forEachMatchingService(Class serviceClass, Consumer<ServiceInfo> consumer);
}
